var http = require('http');
var querystring = require('querystring');

var allmess={
    CompanyId:'0010',
    Source:'wyc1',
    IPCType:'baseinfoCompanyPermit',
    baseinfoCompanyPermit:
        [
            { "CompanyId":"1","Address":"370303","Certificate":"20180503","OperationArea":"淄博","OwnerName":"快车快车","Organization":"快车快车","StartDate":20180101,"StopDate":20220202,"CertifyDate":20200303, "UpdateTime":"20180503221436","State":1,"Flag":1}
        ]

};

/*
for(var j=0;j<3000;j++)
{
    var item={ "CompanyId":"0010","VehicleNo":"6002"+j,"VehicleRegionCode":"370031","PositionTime":"1524321478","Longitude":"118.234",        "Latitude":"36.234","Speed":"29","Direction":"81","Elevation":"31","Mileage":"","Encrypt":"","WarnStatus":"","VehStatus":"","BizStatus":"","OrderId":"003"};
    allmess["positionVehicle"].push(item);
}
*/

var contents = JSON.stringify(allmess);

var buf = new Buffer(contents,'utf8');

var options = {
    host:'127.0.0.1',
    // path:'/api.php/Node/index', port:8001,
    path:'/api.php/baseinfo/companypermit',  port:8001,
    method:'POST',
    headers:{
        'Content-Type':'application/json',
        'Content-Length':buf.length
    }
}

var req = http.request(options, function(res){
    res.setEncoding('utf8');
    res.on('data',function(data){
        console.log("data:",data);   //一段html代码
    });
});

req.on("timeout", function() {
    console.log("timeout received");
    if (req.res) {
        req.res.emit("abort");
    }

    req.abort();
});


//console.log(contents.toString('binary'));
//var buf = new Buffer(contents.toString('binary'),'binary');
req.write(buf);
req.end;